﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2013_ece_csharp_snake
{
    public partial class LoginForm : Form
    {
        protected ConnectionInformation coInf;
        public LoginForm()
        {
            InitializeComponent();

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Visible = true;

            coInf = new ConnectionInformation();
        }

        // Creating a shadow on the border of the form
        protected override CreateParams CreateParams
        {
            get
            {

                CreateParams parameters = base.CreateParams;
                parameters.ClassStyle = (parameters.ClassStyle | 0x00020000);
                return parameters;

            }
        }

        private void uC_SplashScreen1_Load(object sender, EventArgs e)
        {

        }

        // Get Login
        public string getLogin()
        {
            //return this.uC_SplashScreen1.Login;
            return "login";
        }

        // Move the window when click on blanck spaces
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x84:
                    base.WndProc(ref m);
                    if ((int)m.Result == 0x1)
                        m.Result = (IntPtr)0x2;
                    return;
            }

            base.WndProc(ref m);
        }

        // Action en click on Play label: close the form and assign the login
        private void labelPlay_Click(object sender, EventArgs e)
        {
            if (!this.textBoxLogin.Text.ToString().Equals(""))
            {
                this.coInf.myName = this.textBoxLogin.Text.ToString();

                Thread t = new Thread(new ParameterizedThreadStart(startFormDemo));
                t.Start(coInf);

                this.Close();
                this.Dispose();
                this.Visible = false;
            }
            else 
                this.labelLoginText.Text = "We've said: \nenter your name before ;)";

        }

        public static void startFormDemo(Object coInf)
        {
            Application.Run(new WindowsFormsApplication1.FormDemo((ConnectionInformation)coInf));
        }

        private void textBoxLogin_TextChanged(object sender, EventArgs e)
        {

        }

        private void labelLoginText_Click(object sender, EventArgs e)
        {

        }

        private void labelLoginHello_Click(object sender, EventArgs e)
        {

        }

        private void labelReduce_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void labelClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBoxLogin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter) labelPlay_Click(sender, e);
        }
    }
}
